<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>document</title>
    <script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>
    <div id="root">
        <h3>人员列表</h3>
        <ul>
            <!--v-for用于遍历渲染多个dom，这里的person是形参，可以用在插值语法中
                dom的key属性用于指定每个数组元素的唯一标识（可选）
                表达式可以用for in 或 for of语句，不写for
            -->
            <li v-for="person in persons">
                {{person.name}}-{{person.age}}
            </li>
        </ul>

        <h3>人员列表2</h3>
        <ul>
            <!--遍历时可同时拿到index-->
            <li v-for="(person,index) in persons" :key="person.id">
                {{index}}-{{person.name}}-{{person.age}}
            </li>
        </ul>

        <h3>汽车对象</h3>
        <ul>
            <!--v-for遍历对象-->
            <li v-for="(value,key) in car" :key="key">
                {{key}}-{{value}}
            </li>
        </ul>

        <h3>遍历字符串</h3>
        <ul>
            <!--v-for遍历字符串-->
            <li v-for="(ch,index) of 'abcde'" :key="index">
                {{ch}}-{{index}}
            </li>
        </ul>
        
        <h3>遍历指定次数</h3>
        <ul>
            <!--v-for 计数，从1开始计数-->
            <li v-for="(num,index) of 5">
                {{num}}-{{index}}
            </li>
        </ul>
    </div>
    <script>
        Vue.config.productionTip = false

        let vm = new Vue({
            el: "#root", 
            data: { 
                persons:[
                    {
                        id: 101,
                        name: '张三',
                        age: 18
                    },
                    {
                        id: 102,
                        name: '李四',
                        age: 20
                    },
                    {
                        id: 103,
                        name: '王五',
                        age: 23
                    }
                ],
                car:{
                    name:'奥迪A8',
                    price: 200000,
                    color:'黑色',
                }
            },
            methods: {

            },
        })
    </script>
</body>
</html>